<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>姓名案例_计算属性简写</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <!-- 准备好一个容器 -->
    <div id="root">
        姓：<input type="text" v-model="firstname"><br/><br/>
        名：<input type="text" v-model="lastname"><br/><br/>
        全名：<span>{{fullname}}</span>
    </div>
</body>

<script type="text/javascript">
    Vue.config.productionTip = false;   // 阻止vue 在启动时生成生产提示

    const vm = new Vue({
        el: "#root",
        data: {
            firstname: "张",
            lastname: "三"
        },
        computed: {
            // 完整写法
            /*
                fullname: {
                    get() {
                        
                    },
                    set(value) {
                        console.log("set", value);
                        const arr = value.split("-");
                        this.firstname = arr[0];
                        this.lastname = arr[1];
                    }
                }
            */
            // 简写模式  只读不能修改
            fullname() {
                console.log("get被调用了");
                console.log(this);
                return this.firstname.slice(0, 3) + "-" + this.lastname;
            }
            
        }
    })
</script>
</html>